package com.easy.mapper;

import com.easy.bean.Carousel;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface CarouselDao {

    @Select("SELECT id, image_url as imageUrl, title, sort, is_deleted as isDeleted FROM carousel WHERE is_deleted = 0 ORDER BY sort ASC, id DESC")
    List<Carousel> getAll();

    @Insert("INSERT INTO carousel(image_url, title, sort, is_deleted) VALUES(#{imageUrl,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{is_deleted,jdbcType=TINYINT})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(Carousel carousel);

    @Update("UPDATE carousel SET is_deleted = 1 WHERE id = #{id,jdbcType=INTEGER}")
    int delete(Integer id);

    @Select("SELECT id, image_url as imageUrl, title, sort, is_deleted as isDeleted FROM carousel WHERE id = #{id,jdbcType=INTEGER}")
    Carousel getById(Integer id);
}
